<template>
	<view v-show="show" @click.stop="mask?this.$emit('onClose'):''" class="modal-mask">
		<view class="modal-content" :style="{minWidth:minWidth}" @click.stop="">
			<view class="modal-title" v-if="title">{{title}}</view>
			<view class="modal-content-main"><slot>系统提示...</slot></view>
			<view class="modal-content-opt">
				<view class="cancel" v-if="cancel">
					<button plain="true" @click.stop="this.$emit('onOpt', 'cancel')">{{cancelText}}</button>
				</view>
				<view class="ok" v-if="ok">
					<button plain="true" v-if="okType==='share'" open-type="share" @click.stop="this.$emit('onOpt', 'ok')">{{okText}}</button>
					<button plain="true" v-else @click.stop="this.$emit('onOpt', 'ok')">{{okText}}</button>
				</view>
			</view>
			<view class="close-icon" @click="this.$emit('onClose')"><image src="@/static/close.png" mode="aspectFill"/></view>
		</view>
	</view>
</template>

<script>
var that;
export default {
	data() {
		return {
		}
	},
	props: {
		title: {
			type: String, default: ''
		},
		show: {
			type: Boolean,
			default: false
		},
		mask: {
			type: Boolean,
			default: false
		},
		cancel: {
			type: Boolean, default: true
		},
		ok: {
			type: Boolean, default: true
		},
		cancelText: {
			type: String, default: "取消"
		},
		okText: {
			type: String, default: "确定"
		}, 
		minWidth: {
			type: String, default: 'auto'
		},
		okType: {
			type: String, default: 'button'
		}
	},
	created() {
		that = this;
	},
	methods: {
		onMask: function() {
			that = this;
			if(that.mask) {
				that.onClose();
			}
		},
		onClose: function() {
			this.$emit("update:show", false);
			this.$emit("onClose");
		},
	}
}
</script>

<style>
page {
	background: transparent;
}

.modal-title {
	width:100%; text-align: center; line-height: 52rpx; padding-bottom: 16rpx; color:#333; border-bottom: 1px #e0e0e0 solid; font-size:28rpx; margin-bottom: 20rpx;
}

.modal-mask {
	width: 100vw; height: 100vh;
	align-items: center; justify-content: center;
	display: flex; display: -webkit-flex;
	
	position: fixed;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	justify-content: center;
	align-items: center;
	background-color: rgba(0, 0, 0, 0.4);
	z-index: 998;
}

.modal-content {
	background-color: #FFF; padding: 40rpx; 
	position: relative; border-radius: 8rpx; max-height:80vh; margin-top: -10vh;
	width: 80%;
}
.modal-content-main {
	width:100%; max-height: calc(80vh - 240rpx); position: relative;
	overflow: auto; padding-bottom: 30rpx; 
}
.modal-content-opt {
	display: flex;
}
.modal-content-opt view {
	flex:1; line-height: 80rpx; text-align: center;
}
.modal-content-opt view.cancel {
	background:#F8F8F8; color:#888;
}
.modal-content-opt view.ok {
	background:#F4960D; color:#FFF;
}

.modal-content-opt button {
	border: none; background: none;
}
.modal-content-opt view.ok button {
	color:#FFF;
}


.close-icon {
	position: absolute; width: 100rpx; height: 100rpx; align-items: center; justify-content: center;
	display: flex; display: -webkit-flex;
	/* bottom: -45px; left: calc(50% - 20px); */ 
	bottom: -100rpx;
	margin-left: 50%; left: -50rpx;
}
.close-icon image {
	width: 80rpx; height: 80rpx;
}

.modal-text {
	/* #ifndef APP-NVUE */
	display: block;
	/* #endif */
	text-align: center;
	color: #FFFFFF;
}
</style>
